<template>
    <div>
        <div id="main" style="width: 600px;height:400px;">
        </div>
    </div>
</template>

<script>
    /*var echarts = require('echarts');*/
    export default {
        name: "DanaManage",
        data(){
            return{

            }
        },
        methods:{
            initEcharts(){
                this.$getRequest('/data/getDatas').then(resp => {
                    if(resp){
                        let arr1=[];
                        let arr2=[];
                        resp.forEach((item,i)=>{
                            arr1.push(item.counts);
                            arr2.push(item.catename)
                        })
                        // 基于准备好的dom，初始化echarts实例
                        var myChart = this.$echarts.init(document.getElementById('main'));
                        // 绘制图表
                        myChart.setOption({
                            title: {
                                text: '文章类别数量'
                            },
                            tooltip: {},
                            xAxis: {
                                data:arr2
                                /*data: ['衬衫', '羊毛衫', '雪纺衫', '裤子', '高跟鞋', '袜子']*/
                            },
                            yAxis: {},
                            series: [{
                                name: '输量',
                                type: 'bar',
                                data: arr1
                            }]
                        });
                    }
                })
            }
        },
        mounted() {
            this.initEcharts();
        }
    }
</script>

<style scoped>
    #main{
        margin: 50px auto;
    }
</style>